<?php
namespace Homework8;

/**
 * Edge
 * 
 * Explicit data structure needed for graph with weighted edges
 * 
 * @author Taivo
 */
class Edge {
	
	private $to;
	private $from;			/* In the directed graph this needs to be always NULL */
	private $weight;		/* By default the edge weight is 0 */
	
	public function __construct($to = null, $weight = 1) {
		$this->to		= $to;
		$this->from 	= null;
		$this->weight 	= $weight;

	}
	
	public function setFrom(Node $from) {
		$this->from = $from;
	}
	
	public function getFrom() {

		return $this->from;
	}
	
	public function setTo(Node $to) {
		$this->to = $to;
	}
	
	public function getTo(Node $node = null) {
		if ($node == $this->to) { // Needed for undirected graph

			return $this->from;
		}

		return $this->to;
	}
	
	public function setWeight($weight) {
		$this->weight = $weight;
	}
	
	public function getWeight() {
		
		return $this->weight;
	}
	
}